﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;

namespace Server.Controllers
{
    public class UploadController : Controller
    {
        // GET: Upload
        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 上传
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> Upload()
        {
            await Task.Delay(0);
            var filename = HttpContext.Request["filename"];
            var piecefilename = HttpContext.Request["piecefilename"];
            var data = HttpContext.Request.Files["data"];

            var baseDir = @"D:\UploadFiles";

            var filetempDir = Path.Combine(baseDir, Path.GetFileNameWithoutExtension(filename));
            if (!Directory.Exists(filetempDir))
            {
                Directory.CreateDirectory(filetempDir);
            }
            var pieceFilePath = Path.Combine(filetempDir, piecefilename);
            if (!System.IO.File.Exists(pieceFilePath))
            {
                System.IO.File.Create(pieceFilePath).Close();
            }
            return Content("ok");
        }
    }
}